package com.ss.android.article.base.ui;

import android.animation.AnimatorSet;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

public class LoadingFlashView extends FrameLayout {
    private AnimatorSet a;
    private View b;
    private int c;
    private boolean d;

    public LoadingFlashView(Context arg3) {
        super(arg3);
        this.a(arg3, null, 0);
    }

    public LoadingFlashView(Context arg2, AttributeSet arg3) {
        super(arg2, arg3);
        this.a(arg2, arg3, 0);
    }

    public LoadingFlashView(Context arg1, AttributeSet arg2, int arg3) {
        super(arg1, arg2, arg3);
        this.a(arg1, arg2, arg3);
    }

    public final void start() {
        if(this.getVisibility() == View.VISIBLE && (this.d)) {
            if(this.a == null) {
                this.a = new AnimatorSet();
            }

            if(this.a.isRunning()) {
                return;
            }

            if(this.a.isStarted()) {
                return;
            }

            this.a.start();
        }
    }

    private void a(Context arg4, AttributeSet arg5, int arg6) {
        this.b = LayoutInflater.from(arg4).inflate(com.ss.android.article.browser.R.layout.f2, ((ViewGroup)this), false);
        if(arg5 != null) {
            TypedArray v0 = arg4.obtainStyledAttributes(arg5, com.ss.android.article.base.a.K, arg6, 0);
            this.c = v0.getInt(com.ss.android.article.base.a.L, 1);
            v0.recycle();
        }

        this.addView(this.b);
    }

    public final void stop() {
        if(this.a != null && ((this.a.isRunning()) || (this.a.isStarted()))) {
            this.a.removeAllListeners();
            this.a.cancel();
            this.a.end();
        }
    }

    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        this.stop();
    }

    protected void onFinishInflate() {
        super.onFinishInflate();
        this.d = true;
    }

    protected void onLayout(boolean arg6, int arg7, int arg8, int arg9, int arg10) {
        if(this.c == 2) {
            int v0 = (arg9 - arg7 - this.b.getMeasuredWidth()) / 2 + arg7;
            int v1 = (arg10 - arg8 - this.b.getMeasuredHeight()) / 2 + arg8;
            this.b.layout(v0, v1, this.b.getMeasuredWidth() + v0, this.b.getMeasuredHeight() + v1);
        }
        else {
            super.onLayout(arg6, arg7, arg8, arg9, arg10);
        }
    }

    public void setVisibility(int arg1) {
        super.setVisibility(arg1);
        if(arg1 != 0) {
            this.stop();
        }
    }
}

